package org.arch_learn.io.netty_demo.unpacking_demo;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.CharsetUtil;

import java.util.List;

/**
 * 消息编码器
 */
public class MessageEncoder extends MessageToMessageEncoder {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, List list) throws Exception {
        System.out.println("发送消息，并开始进行消息编码...");
        String messageStr = (String) o;
        list.add(Unpooled.copiedBuffer(messageStr, CharsetUtil.UTF_8));
    }
}
